package com.aglhz.nature.adapter;

import java.util.List;



import com.aglhz.nature.R;
import com.aglhz.nature.modle.item.classification.ListData;
import com.aglhz.nature.view.GoodDetailsAcitivty;
import com.squareup.picasso.Picasso;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;

import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class AroundSearchGridViewAdapter extends BaseAdapter{
	public List<ListData>mData;
    public Context context;
    
    
    
	public AroundSearchGridViewAdapter(List<ListData> mData, Context context) {
		super();
		this.mData = mData;
		this.context = context;
	}
	@Override
	public int getCount() {
		return mData.size();
	}
	@Override
	public Object getItem(int position) {
		return  mData.get(position);
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
	@Override
	public View getView(final int position, View convertView, ViewGroup arg2) {
		 ViewHolder viewHolder; 
			if(null==convertView){			
				  convertView = LayoutInflater.from(context).inflate(R.layout.item_around_gridview, null); 
				  viewHolder = new ViewHolder();
				  viewHolder.around_gridview_imageview = (ImageView) convertView.findViewById(R.id.around_gridview_imageview); 
				 
				  viewHolder.around_gridview_imageview.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View arg0) {
					Intent intent =new Intent(context,GoodDetailsAcitivty.class);
					intent.putExtra("detailLink", mData.get(position).getLink());
					Log.e("mData.get(position).getLink()",mData.get(position).getLink());
					context.startActivity(intent);
						
					}
				});
				  viewHolder.around_gridview_goodsName = (TextView) convertView.findViewById(R.id.around_gridview_goodsName); 
				  viewHolder.around_gridview_price = (TextView) convertView.findViewById(R.id.around_gridview_price); 
				  
				  convertView.setTag(viewHolder); 
			}else{
				viewHolder = (ViewHolder) convertView.getTag(); 
			}
			
		/*	
			//设置图片
			
				  String imgUrl = mData.get(position).getPicture();
				//picasso加载网络图片
				   Picasso.with(context) 				  
				   .load(imgUrl) 
				    .resize(getScreenWidth()/3,getScreenWidth()/3)
				   .into(viewHolder.around_gridview_imageview) ;*/
				  
				   
				 //设置名字
					viewHolder.around_gridview_goodsName.setText(mData.get(position).getGoodsName());
					viewHolder.around_gridview_price.setText("￥："+mData.get(position).getPrice());
					Log.e("aaaaaaaaaaa",mData.get(position).getGoodsName());
					Log.e("aaaaaaaaaaa",mData.get(position).getPrice());
					
			int screenWidth = getScreenWidth();
//			GridView.LayoutParams p=new GridView.LayoutParams(screenWidth/3,screenWidth/3);
//			convertView.setLayoutParams(p);

			return convertView;
		}
		class ViewHolder 
		{  
		    public ImageView around_gridview_imageview; 
		    public TextView around_gridview_goodsName;
		    public TextView around_gridview_price;
		} 
		
		/**
		 * 获取屏幕宽度
		 * 
		 * @return
		 */
		protected int getScreenWidth() {
			WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
			Display display = wm.getDefaultDisplay();
			return display.getWidth();
		}
	

}
